import java.util.*;
public class Players extends ArrayList<Player> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	Map voted;
	private String getQ (int n) {
		String str = "";
		for (int i = 0;i < n;i++) {
			str += " 4?";
		}
		return str;
	}
	String getString() {
		String str="";
		for (int i = 0;i<size();i++)
			str += " " + get(i);
		if (str.length() > 1) {
			str=str.substring(1);
		}
		return str;
	}
	String getIDS() {
		String str="";
		for (int i = 0;i<size();i++)
			str += " " + get(i).id;
		if (str.length() > 1) {
			str=str.substring(1);
		}
		return str;
	}
	String inicks () {
		String str="";
		for (int i=0;i<size();i++) {
			str+="," + get(i).inick;
		}
		str=str.substring(1);
		return str;
	}
	public String toString() {
		String players = "";
		String caps = "";
		String medics = "";
		for (int i = 0;i < size();i++) {
			if (get(i).medic)
				medics += " " + get(i).nick;
			else 
				players += " " + get(i).nick;
			if (get(i).cap)
				caps += " " + get(i).nick;
		}
		medics = medics + getQ(2-medics());
		medics = medics.substring(1);
		medics = medics.replaceAll(" "," - ");
		players = players + getQ(10-players());
		players = players.substring(1);
		players = players.replaceAll(" "," - ");
		caps = caps + getQ(2-caps());
		caps = caps.substring(1);
		caps = caps.replaceAll(" "," - ");
		String mapStr = mapsStr();
		if (mapStr.equals(""))
			return "4[ 12(" + caps() + "/2) Captains: 10" + caps + " 4| 12(" + players() + "/10) Players: 10" + players + " 4| 12(" + medics() + "/2) Medics: 10" + medics + " 4]";
		return "4[ 12(" + caps() + "/2) Captains: 10" + caps + " 4| 12(" + players() + "/10) Players: 10" + players + " 4| 12(" + medics() + "/2) Medics: 10" + medics + " 4| 12Votes: " + mapStr + " 4]";
	}
	public boolean contains (String nick) {
		return (getP(nick) != null);
	}
	void remove (String nick) {
		remove(getP(nick));
	}
	void replace (String oldnick, String newnick) {
		getP(oldnick).SetInick(newnick);
	}
	Player getP (String nick) {
		for (int i = 0;i < size();i++) {
			if (get(i).equals(nick)) {
				return get(i);
			}
		}
		return null;
	}
	public void vote(String sender, String vote) {
		getP(sender).setVote(vote);

	}
	int medics () {
		int c = 0;
		for (int i = 0;i < size();i++) {
			if (get(i).medic)
				c++;
		}
		return c;
	}
	Players getMedics () {
		Players medics = new Players();
		for (int i = 0;i < size();i++) {
			if (get(i).medic)
				medics.add(get(i));
		}
		return medics;
	}
	Players getPlayers () {
		Players players = new Players();
		for (int i = 0;i < size();i++) {
			if (!get(i).medic)
				players.add(get(i));
		}
		return players;
	}
	Players getCaps () {
		Players caps = new Players();
		for (int i = 0;i < size();i++) {
			if (get(i).cap)
				caps.add(get(i));
		}
		return caps;
	}
	int caps () {
		int c = 0;
		for (int i = 0;i < size();i++) {
			if (get(i).cap)
				c++;
		}
		return c;
	}
	int players() {
		int c = size();
		for (int i = 0;i < size();i++) {
			if (get(i).medic)
				c--;
		}
		return c;
	}
	String mapsStr() {
		ArrayList<Map> maps = new ArrayList<Map>();
		for (int k = 0;k < size();k++) { 
			String map = get(k).vote;
			boolean isin = false;
			for (int i=0;i<maps.size();i++) {
				if (maps.get(i).equals(map)) {
					isin = true;
				}
			}
			if (!isin) {
				maps.add(new Map(map));
			}
			for (int i=0;i<maps.size();i++) {
				if (maps.get(i).equals(map)) {
					maps.get(i).inc();
				}
			}
		}
		ArrayList<Map> maps2 = new ArrayList<Map>();
		int x = maps.size();
		for (int i = 0;i < x;i++) {
			int big = 0;
			for (int k = 0;k < maps.size();k++) {
				if (maps.get(big).votes < maps.get(k).votes) {
					big = k;
				}
			}
			maps2.add(maps.remove(big));
		}
		maps = maps2;
		String strmaps = "";
		for (int i=0;i<maps.size();i++) {
			if (maps.get(i).getName() != null)
				strmaps += maps.get(i).getName() + "(" + maps.get(i).getVotes() + ") ";
		}
		try {
			voted = maps.get(0);
		} catch (IndexOutOfBoundsException e) {
			voted = null;
		}
		maps.clear();
		return strmaps;
	}
}
